package com.yanqu.road.dao.impl.activity.tongbing.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.tongbing.config.TongBingTitleConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class TongBingTitleConfigDaoImpl extends TempDao {

    private static String getTongBingTitleConfigSql = "select * from `t_s_activity_tongbing_title` where `activityId`=?";

    public Map<Integer, TongBingTitleConfig> getTongBingTitleConfigMap(int activityId) {
        Map<Integer, TongBingTitleConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getTongBingTitleConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                TongBingTitleConfig tongBingTitleConfig = new TongBingTitleConfig();
                tongBingTitleConfig.setActivityId(rs.getInt("activityId"));
                tongBingTitleConfig.setId(rs.getInt("id"));
                tongBingTitleConfig.setType(rs.getInt("type"));
                tongBingTitleConfig.setIcon(rs.getInt("icon"));
                tongBingTitleConfig.setName(rs.getString("name"));
                tongBingTitleConfig.setEffect(rs.getInt("effect"));
                tongBingTitleConfig.setRewards(rs.getString("rewards"));
                map.put(tongBingTitleConfig.getId(), tongBingTitleConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
